

__kernel void iRpropPlus(
	__global float *dEdW, __global float *prevdEdW,
	__global float *delta, __global float *deltaW,
	__global float *parameters,
	float currentError, float prevError,
	float stepDecreaseFactor, float stepIncreaseFactor,
	float stepMinIncrement, float stepMaxIncrement) 
{
	uint i = get_global_id(0);
	
	float errorSign = dEdW[i] * prevdEdW[i];
	if (errorSign > 0) {
		delta[i] = min(stepMaxIncrement, stepIncreaseFactor * delta[i]);
		deltaW[i] = -sign(dEdW[i]) * delta[i]; 
		parameters[i] += deltaW[i];
		prevdEdW[i] = dEdW[i];
	}
	else if (errorSign < 0) {
		delta[i] = max(stepMinIncrement, stepDecreaseFactor * delta[i]);
		if (prevError < currentError) {			
			parameters[i] -= deltaW[i];
		}
		prevdEdW[i] = 0;
	}
	else {
		deltaW[i] = -sign(dEdW[i]) * delta[i];
		parameters[i] += deltaW[i];			
		prevdEdW[i] = dEdW[i];
	}
}